package org.jaaksi.demo.animator;

import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.BounceInterpolator;
import android.widget.ImageView;

/**
 * Created by Fcy on 2015/10/1.<br/>
 * 球体下落
 */
public class FallAnimation extends Activity {

    private ImageView ball;
    private int distance = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.animator_fall);

        ball = (ImageView) findViewById(R.id.ball);
        distance = DensityUtil.dip2px(this, 300);
    }

    public void fall(View view) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(ball, "TranslationY", 0, distance)
            .setDuration(2000);
        animator.setInterpolator(new BounceInterpolator());
        animator.start();
    }

    public void fall2(View view) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(ball, "TranslationY", distance)
            .setDuration(2000);
        animator.setInterpolator(new BounceInterpolator());
        animator.start();
    }
}